﻿using System;
using System.Collections.Generic;
using NHibernate;
using NHibernate.Criterion;
using Ornament.NHibernates;

namespace Ornament.Messages.Dao.NHibernateImple
{
    public class InfoTypeDao : DaoBase<Guid, InfoType>, IInfoTypeDao
    {
        protected override Order[] DefaultOrder
        {
            get { return new Order[] { Order.Asc("Name") }; }
        }





        public IList<InfoType> GetFirstLevel()
        {
            return CreateCriteria().Add(Restrictions.IsNull("OrderId")).List<InfoType>();
        }

        public InfoType Get(string name)
        {
            if (String.IsNullOrEmpty(name))
                throw new ArgumentNullException("name");
            ICriteria criteria = CreateCriteria();
            IList<InfoType> list = criteria.Add(Restrictions.Eq("Name", name)).List<InfoType>();
            if (list.Count == 0)
            {
                throw new ArgumentOutOfRangeException("name",
                                                      String.Format("can't find infoType which name is '{0}'", name));
            }
            return list[0];
        }


    }
}